// app.js
App({
  globalData: {
    userInfo: null,
    // 便便类型
    poopTypes: [
      {
        id: 1,
        name: '正常',
        color: '#34d399',
        icon: 'https://gitee.com/teajoy/image/raw/master/images/正常.png',
        emoji: 'https://gitee.com/teajoy/image/raw/master/images/tabbar/ok.jpeg'
      },
      {
        id: 2,
        name: '异常',
        color: '#f87171',
        icon: 'https://gitee.com/teajoy/image/raw/master/images/异常.png',
        emoji: 'https://gitee.com/teajoy/image/raw/master/images/tabbar/sad.jpg'
      }
    ],
    // 布里斯托大便分类表
    bristolTypes: [
      { id: 1, name: '分散的硬块', description: '难以排出', color: '#f87171' },
      { id: 2, name: '香肠状但结块', description: '较难排出', color: '#f87171' },
      { id: 3, name: '香肠状但表面有裂缝', description: '正常', color: '#fbbf24' },
      { id: 4, name: '香肠状或蛇形，表面光滑', description: '正常', color: '#fbbf24' },
      { id: 5, name: '软块，边缘清晰', description: '偏软', color: '#34d399' },
      { id: 6, name: '糊状，边缘不规则', description: '较软', color: '#34d399' },
      { id: 7, name: '完全液态', description: '腹泻', color: '#34d399' }
    ],
    records: [],
    systemInfo: null,
    menuButtonInfo: null,
    navBarHeight: 0
  },

  onLaunch() {
    try {
      // 从本地存储加载记录
      const records = wx.getStorageSync('poopRecords') || []
      this.globalData.records = records
      
      // 获取系统信息
      const systemInfo = wx.getSystemInfoSync()
      this.globalData.systemInfo = systemInfo
      
      // 获取胶囊按钮位置信息
      const menuButtonInfo = wx.getMenuButtonBoundingClientRect()
      this.globalData.menuButtonInfo = menuButtonInfo
      
      // 计算导航栏高度
      this.globalData.navBarHeight = menuButtonInfo.height + (menuButtonInfo.top - systemInfo.statusBarHeight) * 2
      
      // 检查更新
      this.checkForUpdates()
    } catch (error) {
      // 静默处理初始化错误
    }
  },

  checkForUpdates() {
    if (!wx.canIUse('getUpdateManager')) return

    const updateManager = wx.getUpdateManager()
    updateManager.onCheckForUpdate((res) => {
      if (res.hasUpdate) {
        updateManager.onUpdateReady(() => {
          wx.showModal({
            title: '更新提示',
            content: '新版本已经准备好，是否重启应用？',
            success: (res) => {
              if (res.confirm) {
                updateManager.applyUpdate()
              }
            }
          })
        })
      }
    })
  }
}) 